const router = require('koa-router')()
const userController = require('../controller/userController')
const {sessionCheck} = require('../middlewares/auth')

router.prefix('/users')


router.post('/checkLogin',userController.getUserLogin)

// router.get('/manage',async(ctx)=>{
//   await ctx.render('userManage',{})
// })

router.all('*',sessionCheck)
// router.all('*',async(ctx,next)=>{
//   console.log('/users/checkLogin以外的路由请求')
//   await next()
//   console.log('经过了这个all中间件')
// })

router.get('/welcome',async(ctx)=>{
    await ctx.render('manage',{userName:ctx.session.userName})
})

router.get('/manage',userController.getUserManage)
router.post('/manage',userController.getSearchUserManage)

router.get('/logout',async(ctx)=>{
    ctx.session.userName=[]
    await ctx.render('login',{info:''})
});

module.exports = router
